//学习rust的条件判断：if else 与 match
//学习rust的循环语句：while 与 for 以及 loop

/*
* 阶乘函数，递归实现
*/
fn factorial(m:u32) -> u32 {
	if m == 0 || m == 1 {
		return m;
	}
	
	return factorial(m-1) * m;
}

/*
* 阶乘函数，循环实现
*/
fn factorial_loop(m:u32) -> u32 {
	let mut sum = 1;
	
	/*
	let mut i = 1;
    while i <= m {
        sum *= i;
        i += 1;
    }
	*/
	
	for i in 1..m+1 {
		//说明 1..m+1 是左闭区间
		//println!("i:{}", i);
        sum *= i;
    }
	
    return sum;
}

fn main() {
	
	let res = factorial(10);
	println!("factorial(10) is {}", res);
	
	let res_w = factorial_loop(10);
	println!("factorial_loop(10) is {}", res_w);
}